package com.hjn.spring.knowledgepoints.proxy.jdk.test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MyProxy implements InvocationHandler {
  private Object target;

  public MyProxy(Object target) {
    this.target = target;
  }

  public Object getProxy() {
    return Proxy.newProxyInstance(
        target.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
  }

  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    System.out.println("代理类开始");
    Object invoke = method.invoke(target, args);
    System.out.println("代理类结束");
    return null;
  }
}
